package com.bingxu.flink.chapter02.transformation;

import com.bingxu.flink.bean.WaterSensor;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @author :BingXu
 * @description :TODO
 * @date :2021/8/9 11:34
 * @modifier :
 */

public class Trans_Redistribute {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);
//        DataStreamSource<String> source = env.socketTextStream("localhost", 8989);
        DataStreamSource<WaterSensor> seqDS = env.fromCollection(Arrays.asList(
                new WaterSensor("session_1", 167234633523L, 1),
                new WaterSensor("session_2", 167234633544L, 2),
                new WaterSensor("session_1", 167234633563L, 3),
                new WaterSensor("session_1",167234634555L,0)));

        seqDS.keyBy((KeySelector<WaterSensor, String>) waterSensor -> waterSensor.getId());
        seqDS.print();

        seqDS.rebalance();


        env.execute();

    }
}
